package com.dianping.cat.home.heavy.transform;

import com.dianping.cat.home.heavy.IEntity;
import com.dianping.cat.home.heavy.IVisitor;
import com.dianping.cat.home.heavy.entity.HeavyCache;
import com.dianping.cat.home.heavy.entity.HeavyCall;
import com.dianping.cat.home.heavy.entity.HeavyReport;
import com.dianping.cat.home.heavy.entity.HeavySql;
import com.dianping.cat.home.heavy.entity.Service;
import com.dianping.cat.home.heavy.entity.Url;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  16 */   private Stack<Object> m_objs = new Stack();

  private HeavyReport m_heavyReport;


  public DefaultMerger() {}

  public DefaultMerger(HeavyReport heavyReport) {
    this.m_heavyReport = heavyReport;
    this.m_objs.push(heavyReport);
  }


  public HeavyReport getHeavyReport() { return this.m_heavyReport; }



/*  33 */   protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  37 */     this.m_objs.push(to);
/*  38 */     from.accept(this);
/*  39 */     this.m_objs.pop();
  }


/*  43 */   protected void mergeHeavyCache(HeavyCache to, HeavyCache from) { to.mergeAttributes(from); }



/*  47 */   protected void mergeHeavyCall(HeavyCall to, HeavyCall from) { to.mergeAttributes(from); }



/*  51 */   protected void mergeHeavyReport(HeavyReport to, HeavyReport from) { to.mergeAttributes(from); }



/*  55 */   protected void mergeHeavySql(HeavySql to, HeavySql from) { to.mergeAttributes(from); }



/*  59 */   protected void mergeService(Service to, Service from) { to.mergeAttributes(from); }



/*  63 */   protected void mergeUrl(Url to, Url from) { to.mergeAttributes(from); }



  public void visitHeavyCache(HeavyCache from) {
/*  68 */     HeavyCache to = (HeavyCache)this.m_objs.peek();

/*  70 */     mergeHeavyCache(to, from);
/*  71 */     visitHeavyCacheChildren(to, from);
  }

  protected void visitHeavyCacheChildren(HeavyCache to, HeavyCache from) {
/*  75 */     for (Url source : from.getUrls().values()) {
/*  76 */       Url target = to.findUrl(source.getKey());

      if (target == null) {
/*  79 */         target = new Url(source.getKey());
/*  80 */         to.addUrl(target);
      }

/*  83 */       this.m_objs.push(target);
/*  84 */       source.accept(this);
/*  85 */       this.m_objs.pop();
    }

/*  88 */     for (Service source : from.getServices().values()) {
/*  89 */       Service target = to.findService(source.getKey());

/*  91 */       if (target == null) {
/*  92 */         target = new Service(source.getKey());
/*  93 */         to.addService(target);
      }

/*  96 */       this.m_objs.push(target);
/*  97 */       source.accept(this);
/*  98 */       this.m_objs.pop();
    }
  }


  public void visitHeavyCall(HeavyCall from) {
/* 104 */     HeavyCall to = (HeavyCall)this.m_objs.peek();

/* 106 */     mergeHeavyCall(to, from);
/* 107 */     visitHeavyCallChildren(to, from);
  }

  protected void visitHeavyCallChildren(HeavyCall to, HeavyCall from) {
/* 111 */     for (Url source : from.getUrls().values()) {
/* 112 */       Url target = to.findUrl(source.getKey());

/* 114 */       if (target == null) {
/* 115 */         target = new Url(source.getKey());
/* 116 */         to.addUrl(target);
      }

/* 119 */       this.m_objs.push(target);
/* 120 */       source.accept(this);
/* 121 */       this.m_objs.pop();
    }

/* 124 */     for (Service source : from.getServices().values()) {
/* 125 */       Service target = to.findService(source.getKey());

/* 127 */       if (target == null) {
/* 128 */         target = new Service(source.getKey());
/* 129 */         to.addService(target);
      }

/* 132 */       this.m_objs.push(target);
/* 133 */       source.accept(this);
/* 134 */       this.m_objs.pop();
    }
  }


  public void visitHeavyReport(HeavyReport from) {
/* 140 */     HeavyReport to = (HeavyReport)this.m_objs.peek();

/* 142 */     mergeHeavyReport(to, from);
/* 143 */     visitHeavyReportChildren(to, from);
  }

  protected void visitHeavyReportChildren(HeavyReport to, HeavyReport from) {
/* 147 */     if (from.getHeavySql() != null) {
/* 148 */       HeavySql target = to.getHeavySql();

/* 150 */       if (target == null) {
/* 151 */         target = new HeavySql();
/* 152 */         to.setHeavySql(target);
      }

/* 155 */       this.m_objs.push(target);
/* 156 */       from.getHeavySql().accept(this);
/* 157 */       this.m_objs.pop();
    }

/* 160 */     if (from.getHeavyCall() != null) {
/* 161 */       HeavyCall target = to.getHeavyCall();

/* 163 */       if (target == null) {
/* 164 */         target = new HeavyCall();
/* 165 */         to.setHeavyCall(target);
      }

/* 168 */       this.m_objs.push(target);
/* 169 */       from.getHeavyCall().accept(this);
/* 170 */       this.m_objs.pop();
    }

/* 173 */     if (from.getHeavyCache() != null) {
/* 174 */       HeavyCache target = to.getHeavyCache();

/* 176 */       if (target == null) {
/* 177 */         target = new HeavyCache();
/* 178 */         to.setHeavyCache(target);
      }

/* 181 */       this.m_objs.push(target);
/* 182 */       from.getHeavyCache().accept(this);
/* 183 */       this.m_objs.pop();
    }
  }


  public void visitHeavySql(HeavySql from) {
/* 189 */     HeavySql to = (HeavySql)this.m_objs.peek();

/* 191 */     mergeHeavySql(to, from);
/* 192 */     visitHeavySqlChildren(to, from);
  }

  protected void visitHeavySqlChildren(HeavySql to, HeavySql from) {
/* 196 */     for (Url source : from.getUrls().values()) {
/* 197 */       Url target = to.findUrl(source.getKey());

/* 199 */       if (target == null) {
/* 200 */         target = new Url(source.getKey());
/* 201 */         to.addUrl(target);
      }

/* 204 */       this.m_objs.push(target);
/* 205 */       source.accept(this);
/* 206 */       this.m_objs.pop();
    }

/* 209 */     for (Service source : from.getServices().values()) {
/* 210 */       Service target = to.findService(source.getKey());

/* 212 */       if (target == null) {
/* 213 */         target = new Service(source.getKey());
/* 214 */         to.addService(target);
      }

/* 217 */       this.m_objs.push(target);
/* 218 */       source.accept(this);
/* 219 */       this.m_objs.pop();
    }
  }


  public void visitService(Service from) {
/* 225 */     Service to = (Service)this.m_objs.peek();

/* 227 */     mergeService(to, from);
/* 228 */     visitServiceChildren(to, from);
  }


  protected void visitServiceChildren(Service to, Service from) {}


  public void visitUrl(Url from) {
/* 236 */     Url to = (Url)this.m_objs.peek();

/* 238 */     mergeUrl(to, from);
/* 239 */     visitUrlChildren(to, from);
  }

  protected void visitUrlChildren(Url to, Url from) {}
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/heavy/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */